package com.tuanzi.loan.web.bean.galaxycard;

import com.tuanzi.loan.business.service.galaxycard.GalaxyCardDistributionStatService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.web.configuration.JSFListingBean;

import com.tuanzi.loan.vo.request.galaxycard.DistributionStatSearchRequest;
import com.tuanzi.loan.vo.response.galaxycard.GalaxyCardDistributionStatSearchResponse;
import com.tuanzi.loan.web.lazy.galaxycard.GalaxyCardDistributionStatDataModel;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.faces.bean.ViewScoped;
import java.util.Map;

/**
 * 分销统计
 * @author JinRuiyang 2018/3/1 17:45:19
 */
@Debug
@Data
@Component
@ViewScoped
@EqualsAndHashCode(callSuper = true)
public class GalaxyCardDistributionStatBean extends JSFListingBean<DistributionStatSearchRequest, GalaxyCardDistributionStatSearchResponse> {

    @Autowired
    GalaxyCardDistributionStatService galaxyCardDistributionStatService;

    private Map<String,Integer> channelList;
    private Map<String,String> platformList;
    private Map<String,Integer> productList;

    @PostConstruct
    private void init() {
        initList();
        initLazyDataModel();
    }

    private void initList(){
        channelList = galaxyCardDistributionStatService.getChannel();
        platformList = galaxyCardDistributionStatService.getPlatform();
        productList = galaxyCardDistributionStatService.getProduct();
    }

    public void onReset() {
        initLazyDataModel();
    }

    public void onRefresh(){
        lazyDataModel = new GalaxyCardDistributionStatDataModel($);
        addSuccessfullyMessage();
    }

    private void initLazyDataModel() {
        $ = new DistributionStatSearchRequest();
        lazyDataModel = new GalaxyCardDistributionStatDataModel($);
    }
}